package com.zzyl.controller.customer;

import com.zzyl.base.PageResponse;
import com.zzyl.dto.ReservationDto;
import com.zzyl.entity.CountTime;
import com.zzyl.base.ResponseResult;
import com.zzyl.service.ReservationService;
import com.zzyl.vo.ReservationVo;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@Slf4j
@Api(tags = "参观预约管理")
@RequestMapping("/customer/reservation")
public class CostomerReservationController {

    @Autowired
    private ReservationService reservationService;

    /**
     * 小程序查询取消预约次数
     * @return
     */
    @GetMapping("/cancelled-count")
    public ResponseResult<Integer> getCount(){
        log.info("--小程序查询取消预约次数接口");
        Integer count = reservationService.getCount();
        return ResponseResult.success(count);
    }

    /**
     * 查询每个时间段剩余预约次数
     * @param time
     * @return
     */
    @GetMapping("/countByTime")
    public ResponseResult<List<CountTime>> getCountByTime(@RequestParam Long time){
        log.info("--查询每个时间段剩余预约次数接口，入参time={}",time);
        List<CountTime> countByTimes = reservationService.getCountByTime(time);
        return ResponseResult.success(countByTimes);
    }

    /**
     * 小程序新增预约参观
     * @param reservationDto
     * @return
     */
    @PostMapping
    public ResponseResult addReservation(@RequestBody ReservationDto reservationDto) {
        log.info("小程序新增预约参观,入参={}", reservationDto);
        reservationService.addReservation(reservationDto);
        return ResponseResult.success();
    }

    /**
     * 小程序分页查询预约参观
     * @param pageNum
     * @param pageSize
     * @param status
     * @return
     */
    @GetMapping("/page")
    public ResponseResult<PageResponse<ReservationVo>> getList(@RequestParam Integer pageNum,
                                                               @RequestParam Integer pageSize,
                                                               @RequestParam(required = false) Integer status){
        log.info("小程序分页查询预约参观接口，入参pageNum={}，pageSize={}，status={}",pageNum,pageSize,status);
        PageResponse<ReservationVo> reservationVo = reservationService.getList(pageNum,pageSize,status);
        return ResponseResult.success(reservationVo);
    }

    /**
     * 小程序端取消预约
     * @param id
     * @return
     */
    @PutMapping("/{id}/cancel")
    public ResponseResult removeById(@PathVariable Long id){
        log.info("小程序端取消预约接口，入参id={}",id);
        reservationService.updateById(id);
        return ResponseResult.success();
    }
}
